<html>
<head><meta charset="utf-8"><title>stdlib policy regarding `track_caller` · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stdlib.20policy.20regarding.20.60track_caller.60.html">stdlib policy regarding `track_caller`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="208664665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stdlib%20policy%20regarding%20%60track_caller%60/near/208664665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stdlib.20policy.20regarding.20.60track_caller.60.html#208664665">(Sep 01 2020 at 09:37)</a>:</h4>
<p>Hi,<br>
Is there a policy regarding which functions should be <code>#[track_caller]</code>, I was thinking that it might be user to mark functions that panic because of a user input, but wasn't sure if there's already a policy about that and if everyone will agree with me (I can imagine objections)<br>
Example: here the panic will point at <code>src/liballoc/vec.rs:975:13</code> but I think that because it happened with invalid user input it should be pointed at the caller site.</p>
<div class="codehilite"><pre><span></span><code>fn main() {
    let mut a = vec![1,2,3];
    a.swap_remove(7);
}
</code></pre></div>


<p>The policy I'm thinking about, is if the panic is clearly because of a faulty user input then <code>#[track_caller]</code> should be added.<br>
opinions? (is this considered API and requires t-libs?)</p>



<a name="208665660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stdlib%20policy%20regarding%20%60track_caller%60/near/208665660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stdlib.20policy.20regarding.20.60track_caller.60.html#208665660">(Sep 01 2020 at 09:47)</a>:</h4>
<p>I think it makes sense for that to be <code>#[track_caller]</code>. File a PR and yeah, that'd be in the purview of T-libs. The RFC lays out the policy pretty well I think: <a href="https://github.com/rust-lang/rfcs/blob/master/text/2091-inline-semantic.md#my-fault-vs-your-fault">https://github.com/rust-lang/rfcs/blob/master/text/2091-inline-semantic.md#my-fault-vs-your-fault</a></p>



<a name="208698646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stdlib%20policy%20regarding%20%60track_caller%60/near/208698646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stdlib.20policy.20regarding.20.60track_caller.60.html#208698646">(Sep 01 2020 at 14:54)</a>:</h4>
<p>Does <code>#[track_caller]</code> on a frequently called function (such as in an inner loop) add any overhead?</p>



<a name="208701619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stdlib%20policy%20regarding%20%60track_caller%60/near/208701619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stdlib.20policy.20regarding.20.60track_caller.60.html#208701619">(Sep 01 2020 at 15:13)</a>:</h4>
<p>It also reminds me a bit of the "when do we add <code>#[must_use]</code>" (lack of) policy</p>



<a name="208717397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stdlib%20policy%20regarding%20%60track_caller%60/near/208717397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stdlib.20policy.20regarding.20.60track_caller.60.html#208717397">(Sep 01 2020 at 17:02)</a>:</h4>
<p>well i think must_use is purely docs and warnings (and some ounce of compile time i guess), so in that case there's really no reason to not go all the way with it.</p>
<p>but track_caller probably does have some overhead.</p>



<a name="208717486"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stdlib%20policy%20regarding%20%60track_caller%60/near/208717486" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stdlib.20policy.20regarding.20.60track_caller.60.html#208717486">(Sep 01 2020 at 17:03)</a>:</h4>
<p><code>#[track_caller]</code> at least adds an argument to the annotated function, which can have a cost if the function isn't inlined</p>



<a name="208717627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stdlib%20policy%20regarding%20%60track_caller%60/near/208717627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stdlib.20policy.20regarding.20.60track_caller.60.html#208717627">(Sep 01 2020 at 17:04)</a>:</h4>
<blockquote>
<p>there's really no reason to not go all the way with [<code>must_use</code>]</p>
</blockquote>
<p>Not to derail the conversation about <code>track_caller</code> too much, but it's certainly possible that overuse of <code>must_use</code> will annoy users. If it didn't, then the attribute wouldn't exist and instead _every_ function would warn if you ignored the return value.</p>



<a name="208719198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stdlib%20policy%20regarding%20%60track_caller%60/near/208719198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stdlib.20policy.20regarding.20.60track_caller.60.html#208719198">(Sep 01 2020 at 17:17)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116155">Jake Goulding</span> <a href="#narrow/stream/122651-general/topic/stdlib.20policy.20regarding.20.60track_caller.60/near/208717627">said</a>:</p>
<blockquote>
<blockquote>
<p>there's really no reason to not go all the way with [<code>must_use</code>]</p>
</blockquote>
<p>Not to derail the conversation about <code>track_caller</code> too much, but it's certainly possible that overuse of <code>must_use</code> will annoy users. If it didn't, then the attribute wouldn't exist and instead _every_ function would warn if you ignored the return value.</p>
</blockquote>
<p><a href="https://gankra.github.io/blah/linear-rust/">https://gankra.github.io/blah/linear-rust/</a></p>



<a name="208721748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stdlib%20policy%20regarding%20%60track_caller%60/near/208721748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stdlib.20policy.20regarding.20.60track_caller.60.html#208721748">(Sep 01 2020 at 17:39)</a>:</h4>
<p>Sure, but "linear Rust" ≠ "Rust as currently used by everyone" :-)</p>



<a name="208722850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stdlib%20policy%20regarding%20%60track_caller%60/near/208722850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stdlib.20policy.20regarding.20.60track_caller.60.html#208722850">(Sep 01 2020 at 17:49)</a>:</h4>
<p>right, I was posting this as an example of how it makes things harder to use</p>



<a name="208800724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/stdlib%20policy%20regarding%20%60track_caller%60/near/208800724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/stdlib.20policy.20regarding.20.60track_caller.60.html#208800724">(Sep 02 2020 at 09:47)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/122651-general/topic/stdlib.20policy.20regarding.20.60track_caller.60/near/208698646">said</a>:</p>
<blockquote>
<p>Does <code>#[track_caller]</code> on a frequently called function (such as in an inner loop) add any overhead?</p>
</blockquote>
<p>I think it could; it adds a (typically constant) argument on each call site. so this is probably worth benchmarking.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>